﻿using BrightIdeasSoftware;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Rename.UC.FastOLSV
{
    public class MultiButtonRenderer:BaseRenderer
    {
        private List<Rectangle> buttonRectangles = new List<Rectangle>();
        private const int ButtonSpacing = 15;
        private const int ButtonSize = 32;

        public List<Image> ButtonImages { get; set; } = new List<Image>();
        public List<Action<OlvListViewHitTestInfo>> ButtonActions { get; set; } = new List<Action<OlvListViewHitTestInfo>>();

        public override void Render(Graphics g, Rectangle r)
        {
            DrawBackground(g, r);
            buttonRectangles.Clear();
            int x = r.Left+5;

            for (int i = 0; i < ButtonImages.Count; i++)
            {
                Rectangle btnRect =new Rectangle();
                if (ButtonImages[i] != null)
                {
                    btnRect = new Rectangle(x, r.Top+(r.Height-ButtonSize)/2,ButtonSize, ButtonSize);
                }
                // 绘制按钮
                if (btnRect.Contains(Column.ListView.PointToClient(Cursor.Position)))
                {
                    using (Brush brush = new SolidBrush(Color.FromArgb(119, 203, 224)))
                    {
                        g.FillRectangle(brush,btnRect);
                    }
                }
                g.DrawImage(ButtonImages[i], btnRect);
                buttonRectangles.Add(btnRect);
                x += ButtonSize + ButtonSpacing;
            }
        }
        protected override void HandleHitTest(Graphics g, OlvListViewHitTestInfo hti, int x, int y)
        {
            //base.HandleHitTest(g, hti, x, y);
            for (int i = 0; i < buttonRectangles.Count; i++)
            {
                if (buttonRectangles[i].Contains(x, y))
                {
                    hti.HitTestLocation = HitTestLocation.Button;
                    hti.UserData = i; // 存储按钮索引
                    break;
                }
            }
        }
    }
}
